<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>3-width的两种宽度</title>
    <style>
        html {
            font-size: 30px;
        }

        .main-percernt-100 {
            background-color: red;
            width: 700px;
            font-size: 30px;
            color: #fff;
            height: 80px;
        }

        .right {
            background: green;
            height: 40px;
            width: 100%;
        }

        .right-padding-padding-left-100 {
            background: green;
            height: 40px;
            width: 100%;
            padding-left: 100px;
        }

        .right-padding-margin-left-100 {
            background: green;
            height: 40px;
            width: 100%;
            margin-left: 100px;
        }

        .main-auto {
            background-color: red;
            width: 700px;
            font-size: 30px;
            color: #fff;
            height: 80px;
        }

        .right-auto {
            background: green;
            height: 40px;
            width: auto;
        }

        .right-auto-padding-left-100 {
            background: green;
            height: 40px;
            width: auto;
            padding-left: 100px;
        }

        .right-auto-margin-left-100 {
            background: green;
            height: 40px;
            width: auto;
            margin-left: 100px;
        }
    </style>
</head>

<body>
    <div>当width=100%时,子元素的宽度是继承的父元素宽度,不包括子元素设置的margin padding 和border部分
    </div>
    <hr>
    <div class="main-percernt-100">
        <div class="right">right</div>
    </div>
    <hr>
    <div>此时如果left设置padding值的话例如padding-left：100px,会变成下面这样
    </div>
    <div class="main-percernt-100">
        <div class="right-padding-padding-left-100">right</div>
    </div>
    <hr>
    <div class="main-percernt-100">
        <div class="right-padding-margin-left-100">right</div>
    </div>

    <hr>
    <hr>
    <hr>
    <div>
        当width=auto时,父元素的width=子元素的width+子元素border+子元素margin+子元素padding
    </div>
    <hr>
    <div class="main-auto">
        <div class="right-auto">auto right</div>
    </div>
    <hr>
    <div class="main-auto">
        <div class="right-auto-padding-left-100">padding-left-100</div>
    </div>
    <hr>
    <div class="main-auto">
        <div class="right-auto-margin-left-100">margin-left-100</div>
    </div>

</body>

</html>